#include <stdio.h>

void ChooseSort2(int *a,int len)
{
    int left = 0;
    int right = len - 1;
    while(left < right)
    {
        int min = left;
        int max = right;
        for(int i = left; i <= right; i++)
        {
            if(a[i] < a[min])
            {
                min = i;
            }
            if(a[i] > a[max])
            {
                max = i;
            }
        }
        int temp = a[left];
        a[left] = a[min];
        a[min] = temp;
        

        if(left == max)
        {
            max = min;
        }

        temp = a[right];
        a[right] = a[max];
        a[max] = temp;

        left++;
        right--;
    }
} 

int main()
{
    int a[] = {34,42,1,43,6,3};
    ChooseSort2(a,6);
    for(int i = 0; i < 6; i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
    return 0;
}